DAY18:Highest and Lowest


Posted by birdbirdmurmur on 2023-07-31

題目連結

Highest and Lowest

解法

Javscript

function highAndLow(numbers){
  const numbersArray = numbers.split(' ').map(Number);
  const maxNumber = Math.max(...numbersArray);
  const minNumber = Math.min(...numbersArray);
  return (`${maxNumber} ${minNumber}`)
}

Typescript

function highAndLow(numbers: string): string {
  const numbersArray: number[] = numbers.split(' ').map(Number);
  const maxNumber: number = Math.max(...numbersArray);
  const minNumber: number = Math.min(...numbersArray);
  return `${maxNumber} ${minNumber}`;
}

筆記

首先將原本傳入的number:string轉換成數字陣列
使用Math.maxMath.min可以快速找到最大值和最小值
...
最近開始練習Typescript
與Javascript交互比對可以更了解型別


#javascript #TypeScript #Codewars







Related Posts

From Nand To Tetris:想理解電腦運作,就先做出一台吧!

From Nand To Tetris:想理解電腦運作,就先做出一台吧!

『Android』ADB Debug by wifi 用Wifi連線來Debug

『Android』ADB Debug by wifi 用Wifi連線來Debug

[ 前端工具 ] - gulp, Babel, SCSS, uglyfy

[ 前端工具 ] - gulp, Babel, SCSS, uglyfy


Comments